package com.project.filter;

import com.project.bean.UserBean;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/8/2 14:23
 */
public class AssFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        //从session中得到登录用户信息
        UserBean userBean = (UserBean) request.getSession().getAttribute("loginUserBean");
        if (userBean == null) {
            response.sendRedirect("/html/login.html?errorInfo=noland");
        } else if (userBean.getPower().equals("经理")) {
            filterChain.doFilter(request, response);
        } else {
            response.sendRedirect("/html/login.html?errorInfo=nograde");
        }
    }
}
